import os

path = "Resor"
albumdir = "/media/storage/Pictures/webalbum"

#albumdir = os.path.abspath(os.curdir)
"""print "path: %s"%(path)

requested_path = os.path.join(albumdir, path)
print "requested_path: %s"%(requested_path)

requested_path = os.path.relpath(requested_path, albumdir)
print "os.path.relpath: %s"%(requested_path)

requested_path = os.path.abspath(requested_path)
print "os.path.abspath: %s"%(requested_path)

print "common prefix %s"%os.path.commonprefix([requested_path, albumdir])"""


requested_path = path #os.path.join(albumdir, path)
print("requested_path: %s"%(requested_path))
absolute_path = os.path.join(albumdir, requested_path)
print("absolute_path: %s"%(absolute_path))
normalized_path = os.path.normpath(absolute_path)
print("normalized_path: %s"%(normalized_path))

# security check to prevent directory traversal
if not normalized_path.startswith(albumdir):
    print("ServerSide::validPath() Error: Invalid path detected! requested_path: %s"%(requested_path))

